package com.example.intentdataandtype;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	private Button browserBtn = null;
	private Button editBtn = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		browserBtn = (Button) this.findViewById(R.id.maina_id_browser_btn);
		editBtn = (Button) this.findViewById(R.id.maina_id_edit_btn);

		browserBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 创建Intent
				Intent intent = new Intent();
				String data = "http://www.baidu.com";
				// 根据指定串解析出Uri对象
				Uri uri = Uri.parse(data);
				// 为Intent设置Action属性
				intent.setAction(Intent.ACTION_VIEW);
				// 设置Data属性
				intent.setData(uri);
				startActivity(intent);
			}
		});
		editBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// 创建Intent
				Intent intent = new Intent();
				// 为Intent 设置Action属性(动作为：编辑)
				intent.setAction(Intent.ACTION_EDIT);
				String data = "content://com.android.contacts/contacts/1";
				Uri uri = Uri.parse(data);
				// 设置Data属性
				intent.setData(uri);
				startActivity(intent);
			}
		});

	}

	/**
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
